<template>
  <div class="form-layout ">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor :itemList="[
        { name: 'box-base', title: '开票信息' },
        { name: 'box-sp', title: '供方开票信息' },
        { name: 'box-hp', title: '院方开票信息' },
        { name: 'box-dtl', title: '开票明细' },
        { name: 'box-file', title: '发票附件' }]" />
    </div>
    <!--表单区域-->
    <div class="form-right" ref="formRight">
      <customForm :data="form" :rules="propRules" ref="editForm" :disabled="propReadonly">
        <template #content>
          <div id="box-base" class="box-title">开票信息</div>
          <customFormItem label="发票号" name="invoiceNo" :parent="_self" :form="form" />
          <customFormItem label="开票单号" name="code" :parent="_self" :form="form" disabled/>
          <customFormItem label="期号" name="periodNo" :parent="_self" :form="form"  disabled/>
          <customFormItem label="开票时间" name="gmtMakeOut" :parent="_self" :form="form"  disabled/>
          <customFormItem label="开票人" name="drawer" :parent="_self" :form="form"  disabled/>
          <customFormItem label="医院" name="hospitalName" :parent="_self" :form="form"  disabled/>
          <customFormItem label="供应商" name="supplierName" :parent="_self" :form="form"  disabled/>
          <customFormItem label="开票金额" name="totalAmount" :parent="_self" :form="form"  disabled/>
          <customFormItem label="汇总条件" name="groupByCondition" :parent="_self" :form="form"  disabled
                :type="constCommon.formItemType.selectStatic.name"
                :config="{options: constCommon.busConst.invoiceGroupList}"
          />
          <customFormItem label="状态" name="status" :parent="_self" :form="form"
                          :type="constCommon.formItemType.selectDict.name"
                          :config="{dictType: constCommon.dictType.settlementInvoiceStatus}"  disabled
          />
          <customFormItem label="审核人" name="auditorName" :parent="_self" :form="form"  disabled v-if="strings.isNotBlank(form.auditorName)"/>
          <customFormItem label="审核时间" name="gmtAudited" :parent="_self" :form="form"  disabled  v-if="strings.isNotBlank(form.auditorName)"/>
          <customFormItem label="备注" name="remark" :parent="_self" :form="form" />

          <div id="box-sp" class="box-title">供方开票信息</div>
          <customFormItem label="名称" name="spInvoiceName" :parent="_self" :form="form"  disabled/>
          <customFormItem label="税号" name="spInvoiceNo" :parent="_self" :form="form"  disabled/>
          <customFormItem label="单位地址" name="spInvoiceAddress" :parent="_self" :form="form"  disabled/>
          <customFormItem label="电话号码" name="spInvoiceTel" :parent="_self" :form="form"  disabled/>
          <customFormItem label="开户银行" name="spInvoiceBankName" :parent="_self" :form="form"  disabled/>
          <customFormItem label="银行账号" name="spInvoiceBankNo" :parent="_self" :form="form"  disabled/>

          <div id="box-hp" class="box-title">院方开票信息</div>
          <customFormItem label="名称" name="hosInvoiceName" :parent="_self" :form="form"  disabled/>
          <customFormItem label="税号" name="hosInvoiceNo" :parent="_self" :form="form"  disabled/>
          <customFormItem label="单位地址" name="hosInvoiceAddress" :parent="_self" :form="form"  disabled/>
          <customFormItem label="电话号码" name="hosInvoiceTel" :parent="_self" :form="form"  disabled/>
          <customFormItem label="开户银行" name="hosInvoiceBankName" :parent="_self" :form="form"  disabled/>
          <customFormItem label="银行账号" name="hosInvoiceBankNo" :parent="_self" :form="form"  disabled/>

          <div id="box-dtl" class="box-title">开票明细</div>
          <data-view
            propViewKey="bill_item_for_invoice_audit"
            :propIsTdesign="true"
            :propParentPage="_self"
            ref="childDataView"
            :propAutoFetchData="false"
            :propTableHide="!form.id"
            :propOnlyQueryAll="propReadonly"
            :propInitData="form"
            @afterTableDataChange="afterTableDataChange"
          />

          <div id="box-file" class="box-title">发票附件</div>
          <customFormItem
            label=""
            name="fileInfo"
            :parent="_self"
            :form="form"
            :type="constCommon.formItemType.slot.name"
            fullWidth
            style="padding-left: 10px;"
          >
            <template #content>
              <customUpload
                :data="{ fileRefId: form.id, fileRefTable: 'invoice', fileSavePath: 'invoice'}"
                :hide="propParent.cpFormNew"
                hideMsg="请先保存后再上传"
                :max="20"
                :disabled="propReadonly"
                multiple
                theme="file"
              />
            </template>
          </customFormItem>
        </template>
      </customForm>
    </div>
  </div>
</template>

<script>
import customAnchor from '@/components/custom/form/customAnchor.vue'
import customUpload from '@/components/custom/form/customUpload.vue'
export default {
  help: '开票单审核-详情',
  data() {
    return {
      form: {},
      viewData: {},
    }
  },
  methods: {
    // 加载明细数据
    fetchChildData() {
      let queryWrapper = this.$newWrapper()
      if (this.form.id) {
        queryWrapper.eq('invoiceId', this.form.id)
      } else {
        queryWrapper.ne(1, 1)
      }
      this.$refs.childDataView.setQueryWrapper(queryWrapper)
    },

    // 明细 新增、删除、修改后调用
    afterTableDataChange() {
      this.utils.refreshRefs(this)
    },
  },
  created() {
    let that = this
    this.$emit('event-register', {
      validate: (callback) => {
        return this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData) => {
        this.form = global.utils.jsonClone(formData)
        this.$set(this.form, 'id', this.form.id)
        this.fetchChildData()
      },
      afterSave: () => {
      },
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {
      },
      beforeFlow: (flowButtonKey) => {
        return true
      },
      afterFlow: (flowButtonKey) => {
      },
      beforeClose: () => {
        return true
      },
      afterClick(button, data) {
        let {key: buttonKey} = button
        if (buttonKey == 'printForm') { // 打印开票单
          let token = global.utils.getToken()
          that.utilPrint.openPdfView(`打印开票单-${that.form.code}`, `${global.utils.getBaseUrlFull()}/settlement/invoices/${that.form.id}/pdf-preview?X-Token=${token}`)
        }
      },
    })
  },
  props: {
    propParent: Object,
    propInitData: Object,
    propPrimaryKey: String,
    propDictionaries: Object,
    propCurrentRow: Object,
    propViewFormData: Object,
    propReadonly: Boolean,
    propStatus: String,
    propRules: Object,
  },
  components: { customUpload, customAnchor},
  computed: {
  },
}
</script>
